package cn.edu.hncj.Service.Impl;

import cn.edu.hncj.Dao.UserDao;
import cn.edu.hncj.Service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @Auther: Lix
 * @Date: 2024/11/17 - 11 - 17 - 11:41
 * Description: cn.edu.hncj.Service.Impl
 * Version: 1.0
 */

//<bean id="userService" class="cn.edu.hncj.Service.Impl.UserServiceImpl">
// @Component("userService")
@Service("userService")
@Scope("singleton")
public class UserServiceImpl implements UserService {

    @Value("${jdbc.driver}")
    private String Driver;

    //注解注入
    //<property name="userDao" ref="userDao"></property>
    // @Autowired    //根据类型从spring容器中进行匹配
    // @Qualifier("userDao")   //根据id值从spring容器中进行匹配。注意：@Qualifier要和@Autowired一起使用
    @Resource(name = "userDao")  //@Resource 等同于 @Qualifier ＋ @Autowired
    private UserDao userDao;


    public void save() {
        System.out.println(Driver);
        userDao.save();
    }

    @PostConstruct
    public void init(){
        System.out.println("userService对象初始化方法执行...");
    }
    @PreDestroy
    public void destory(){
        System.out.println("userService对象销毁方法执行...");
    }
}
